<?php
/**
 * BannerController
 *
 * PHP Version 5.4
 *
 * @author liuxu <liuxuphp@icesmart.cn>
 */

namespace Api\Controller;

use Model\AdModel;
use Think\Controller;

class BannerController extends BaseController
{
    /**
     * 广告列表
     * @http-method GET
     */
    public function find()
    {
        $url = '/Api/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        $validate = $this->validateInterface($url);
        if(!$validate){
            $result['code'] = 404;
            $result['msg'] = '此接口已被禁用';

            $this->ajaxReturn($result, 'JSON');
        }
        $filter['status'] = 1;

        $bannerModel = new AdModel();
        $bannerList = $bannerModel->findByFilter($filter);
        foreach($bannerList as $k => $v){
            $bannerList[$k]['image'] = $_SERVER["SERVER_NAME"].'/'.$v['image'];
        }

        $result = [];
        if($bannerList){
            $result['code'] = 200;
            $result['msg'] = $bannerList;
        }else{
            $result['code'] = 404;
            $result['msg'] = '广告不存在';
        }

        $this->ajaxReturn($result, 'JSON');
    }
} 